//
//  HNSH_PassFriendViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/6.
//

#import "HNSH_PassFriendViewController.h"
#import "HNSH_ReportViewController.h"
#import "HNSH_VerifyFriendViewController.h"

@interface HNSH_PassFriendViewController ()

/** */
@property (nonatomic, strong)UIView * bgView;
/** */
@property (nonatomic, strong)UIImageView * imgView;
/** */
@property (nonatomic, strong)UILabel * nameLabel;
/** */
//@property (nonatomic, strong)DLUserLevelView * levelView;
/** */
@property (nonatomic, strong)UILabel * phoneLabel;
/** */
@property (nonatomic, strong)UIView * textBgView;
/** */
@property (nonatomic, strong)UITextField * textField;
/** */
@property (nonatomic, strong)UIView * segView;
/** */
@property (nonatomic, strong)UIView * reportView;
/** */
@property (nonatomic, strong)UILabel * titleLabel;
/** */
@property (nonatomic, strong)UIImageView * rightImgView;
/** */
@property (nonatomic, strong)UIButton * sendBtn;

@end

@implementation HNSH_PassFriendViewController

//MARK: Cycle Methods
- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self showNavTitle:self.model.user.name showLeftItem:YES];
    
    [self addAllViews];
    [self addAllLayout];
}

- (void)addAllViews{
    [self.view addSubview:self.bgView];
    [self.bgView addSubview:self.imgView];
    [self.bgView addSubview:self.nameLabel];
//    [self.bgView addSubview:self.levelView];
    [self.bgView addSubview:self.phoneLabel];
    [self.bgView addSubview:self.textBgView];
    [self.textBgView addSubview:self.textField];
    [self.bgView addSubview:self.segView];
    [self.bgView addSubview:self.reportView];
    [self.reportView addSubview:self.titleLabel];
    [self.reportView addSubview:self.rightImgView];
    [self.view addSubview:self.sendBtn];
}

- (void)addAllLayout{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.top.mas_equalTo(kNavBarAndStatusBarHeight   + 8);
        make.height.mas_equalTo(232);
    }];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(24);
        make.width.height.mas_equalTo(72);
        make.top.mas_equalTo(19);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(30);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(16);
        make.height.mas_equalTo(25);
    }];
//    [self.levelView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(4);
//        make.left.mas_equalTo(self.nameLabel);
//        make.height.mas_equalTo(22);
//    }];
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(4);
        make.left.right.mas_equalTo(self.nameLabel);
        make.height.mas_equalTo(22);
    }];
    [self.textBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imgView.mas_bottom).offset(20);
        make.left.mas_equalTo(self.imgView);
        make.right.mas_equalTo(-24);
        make.height.mas_equalTo(32);
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.top.bottom.mas_equalTo(0);
    }];
    [self.segView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.textBgView.mas_bottom).offset(37);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    [self.reportView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.segView.mas_bottom);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(24);
        make.bottom.mas_equalTo(0);
    }];
    [self.rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-23);
        make.width.mas_equalTo(10);
        make.height.mas_equalTo(14);
        make.centerY.mas_equalTo(self.reportView);
    }];
    [self.sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(48);
        make.top.mas_equalTo(self.bgView.mas_bottom).offset(6);
    }];
}

//MARK: Custom Methods
- (void)gesAction{
    HNSH_ReportViewController * vc = [HNSH_ReportViewController new];
    vc.rcUserId = self.model.user.uid;
    vc.name = self.model.user.display_name.length ? self.model.user.display_name : self.model.user.name;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)sendBtnAction{
    HNSH_VerifyFriendViewController * vc = [HNSH_VerifyFriendViewController new];
    vc.targetId = self.model.user.user_id;
    vc.message = self.model.message;
    vc.rcUserId = self.model.user.uid;
    [self.navigationController pushViewController:vc animated:YES];
}

//MARK: Setter Methods
- (void)setModel:(HNSH_ChatFriendModel *)model{
    _model = model;
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.user.portrait] placeholderImage:[UIImage imageNamed:@"base_user_header_icon"]];
    self.nameLabel.text = model.user.name;
    self.phoneLabel.text = model.user.phone;
    self.textField.text = self.model.message;
    NSDictionary * extra = [model.user.extra jsonValueDecoded];
//    self.levelView.level = [extra[@"creditLevel"] integerValue];
}

//MARK: Getter Methods
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 8;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.layer.cornerRadius = 8;
        _imgView.layer.masksToBounds = YES;
        _imgView.image = [UIImage imageNamed:@"base_user_header_icon"];
    }
    return _imgView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.font = [UIFont boldSystemFontOfSize:18];
        _nameLabel.textColor = [UIColor appBlack333LabelColor];
    }
    return _nameLabel;
}

//- (DLUserLevelView *)levelView{
//    if (!_levelView) {
//        _levelView = [DLUserLevelView new];
//    }
//    return _levelView;
//}

- (UILabel *)phoneLabel{
    if (!_phoneLabel) {
        _phoneLabel = [UILabel new];
        _phoneLabel.font = [UIFont systemFontOfSize:16];
        _phoneLabel.textColor = [UIColor appBlack333LabelColor];
    }
    return _phoneLabel;
}

- (UIView *)textBgView{
    if (!_textBgView) {
        _textBgView = [UIView new];
        _textBgView.backgroundColor = [UIColor colorWithHexString:@"#FAFAFC"];
        _textBgView.layer.cornerRadius = 4;
        _textBgView.layer.masksToBounds = YES;
        _textBgView.layer.borderColor = [UIColor colorWithHexString:@"#E6E6E6"].CGColor;
        _textBgView.layer.borderWidth = 1;
    }
    return _textBgView;
}

- (UITextField *)textField{
    if (!_textField) {
        _textField = [UITextField new];
        _textField.font = [UIFont systemFontOfSize:12];
        _textField.textColor = [UIColor appBlack333LabelColor];
    }
    return _textField;
}

- (UIView *)segView{
    if (!_segView) {
        _segView = [UIView new];
        _segView.backgroundColor = [UIColor colorWithHexString:@"#EDEDED"];
    }
    return _segView;
}

- (UIView *)reportView{
    if (!_reportView) {
        _reportView = [UIView new];
        _reportView.backgroundColor = [UIColor whiteColor];
        
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gesAction)];
        [_reportView addGestureRecognizer:tap];
    }
    return _reportView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = [UIColor appBlack333LabelColor];
        _titleLabel.text = @"举报用户";
    }
    return _titleLabel;
}

- (UIImageView *)rightImgView{
    if (!_rightImgView) {
        _rightImgView = [UIImageView new];
        _rightImgView.image = [UIImage imageNamed:@"buy_right"];
    }
    return _rightImgView;
}

- (UIButton *)sendBtn{
    if (!_sendBtn) {
        _sendBtn = [UIButton new];
        [_sendBtn setTitle:@"前往验证" forState:UIControlStateNormal];
        [_sendBtn setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
        _sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        _sendBtn.backgroundColor = [UIColor whiteColor];
        _sendBtn.layer.cornerRadius = 4;
        _sendBtn.layer.masksToBounds = YES;
        [_sendBtn addTarget:self action:@selector(sendBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sendBtn;
}

@end
